/*前台分页JS*/
$(function () {
	if(Number($("[name='totalCount']").val()) > 0){
	    var pages = [],
	    totalPage = Number($("[name='totalPage']").val()),
	    totalCount = Number($("[name='totalCount']").val()),
	    currentPage = Number($("[name='currentPage']").val())==0 ? 1 :Number($("[name='currentPage']").val());
	    pages[pages.length] = '<ul class="page_scroll"><li id="prev" class="page_num">&#171; </li>';
	    if (currentPage < 5) {
	        for (var i = 1; i <= (totalPage > 10 ? 10 : totalPage); i++) {
	            if (currentPage == i)
	            	pages[pages.length] = '<li class="page_num_on">' + i + '</li>';
	            else
	            	pages[pages.length] = '<li class="page_num">' + i + '</li>';
	        }
	    }
	    else if (currentPage >= totalPage - 5)
	    	for (var i = totalPage - 9; i <= totalPage; i++) {
	            if (currentPage == i)
	            	pages[pages.length] = '<li class="page_num_on">' + i + '</li>';
	            else
	            	pages[pages.length] = '<li class="page_num">' + i + '</li>';
	        }
	    else {
	    	for (var i = currentPage - 4; i <= currentPage + 5; i++) {
	            if (currentPage == i)
	            	pages[pages.length] = '<li class="page_num_on">' + i + '</li>';
	            else
	            	pages[pages.length] = '<li class="page_num">' + i + '</li>';
	        }
	    }
	    pages[pages.length] = '<li id="next" class="page_num">&#187; </li></ul>';
	    $(".page_side").html(pages.join("")).find("li:not(#next):not(#prev)").click(function(){
	    	$("[name='currentPage']").val($(this).text());
	    	$("#searchFrom").submit();
	    });
	    $(".page_side").find("li#prev").click(function(){
	    	num = Number($("[name='currentPage']").val()) - 1 < 1 ? 1 :Number($("[name='currentPage']").val()) - 1;
	    	$("[name='currentPage']").val(num);
	    	$("#searchFrom").submit();
	    });
	    $(".page_side").find("li#next").click(function(){
	    	num = Number($("[name='currentPage']").val()) + 1 > totalPage ? totalPage :Number($("[name='currentPage']").val()) + 1;
	    	$("[name='currentPage']").val(num);
	    	$("#searchFrom").submit();
	    });
    }
});